﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SachVietDLL;
using SachVietDLL.BLL;

namespace SachViet.Controllers
{
    public class CatelogyController : Controller
    {
        private CategoryBLL category = new CategoryBLL();

        //
        // GET: /Catelogy/

        public ActionResult Index()
        {
            return View(category.GetAllCategory().ToList());
        }

        //
        // GET: /Catelogy/Details/5

        public ActionResult Details(string id = null)
        {
            Book_Category book_category = category.GetCategoryByID(id);
            if (book_category == null)
            {
                return HttpNotFound();
            }
            return View(book_category);
        }

        //
        // GET: /Catelogy/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Catelogy/Create

        [HttpPost]
        public ActionResult Create(Book_Category book_category)
        {
            if (ModelState.IsValid)
            {
                category.Create(book_category);
                return RedirectToAction("Index");
            }

            return View(book_category);
        }

        //
        // GET: /Catelogy/Edit/5

        public ActionResult Edit(string id = null)
        {
            Book_Category book_category = category.GetCategoryByID(id);
            if (book_category == null)
            {
                return HttpNotFound();
            }
            return View(book_category);
        }

        //
        // POST: /Catelogy/Edit/5

        [HttpPost]
        public ActionResult Edit(Book_Category book_category)
        {
            if (ModelState.IsValid)
            {
                category.Edit(book_category);
                return RedirectToAction("Index");
            }
            return View(book_category);
        }

        //
        // GET: /Catelogy/Delete/5

        public ActionResult Delete(string id = null)
        {
            Book_Category book_category = category.GetCategoryByID(id);
            if (book_category == null)
            {
                return HttpNotFound();
            }
            return View(book_category);
        }

        //
        // POST: /Catelogy/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            category.Delete(id);
            return RedirectToAction("Index");
        }

    }
}